import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { LazyLoadEvent, SelectItem } from 'primeng/api';
import { FormRepositoryService } from './fb-repository.service';

@Component({
  selector: 'fb-repository',
  templateUrl: './fb-repository.component.html',
  styleUrls: [ './fb-repository.component.scss' ],
  providers: [ FormRepositoryService ]
})
export class FormRepositoryComponent implements OnInit {
  forms: any[];
  totalRecords: number;
  loading: boolean;
  constructor(
    private router: Router,
    private formRepositoryService: FormRepositoryService) {
    this.forms = []; 
  }

  ngOnInit() {
  }

  formItemClick(rowData){
    this.router.navigate(['/form/repodetail', { "id": rowData.formId }]);
  }
  
  loadLazy(event: LazyLoadEvent) {
    let params = { 'pageSize': 12, 'pageNum': event.first / event.rows};
    this.loading = true;
    this.formRepositoryService.listRepositoryPage(params).subscribe(data => {
        this.loading = false;
        this.totalRecords = data.total;
        this.forms = data.list;
    })
}
}
